<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class MFileVersions extends MModel {
    
    public static function queryFileVersionByID($id) {
        $db_manager = MDbManager::getInstance();
        $sql = "select * from " . DB_PREFIX . "_file_versions where id=$id";
        FXP::trace("function: '{queryFileVersionByID}',sql:'{$sql}'");
        
        return $db_manager->selectDb($sql);
    }
    
    
    public static function queryFileVersionBySignatrue($signatrue) {
        $db_manager = MDbManager::getInstance();
        $sql = "select * from " . DB_PREFIX . "_file_versions where file_signature=\"$signatrue\"";
        FXP::trace("function: '{queryFileVersionBySignatrue}',sql:'{$sql}'");
        
        return $db_manager->selectDb($sql);
    }
    
    
    public static function createFileVersion($signature, $size, $mime_type) {
                                $sql  = "insert into " . DB_PREFIX . "_file_versions";
        $sql .= "(file_signature,file_size,block_ids,ref_count,mime_type,created_at,updated_at)";
        $sql .= " VALUES(";
        $sql .= "\"$signature\",$size,'0',0,\"$mime_type\",now(),now()";
        $sql .= ")";
        FXP::trace("function: '{__FUNCTION__}',sql:'{$sql}'");
        $db_manager = MDbManager::getInstance();
        return $db_manager->insertDb($sql);
    }
    
    
    public static function updateRefCountById($id) {
        $sql  = "UPDATE " . DB_PREFIX . "_file_versions ";
        $sql .= "SET ref_count = ref_count + 1, updated_at = now() ";
        $sql .= "WHERE id=$id";
        FXP::trace("function: '{__FUNCTION__}',sql:'{$sql}'");
        $db_manager = MDbManager::getInstance();
        return $db_manager->updateDb($sql);
    }
}
?>